package com.yhb.controller;

import com.yhb.controller.vo.SingleValueWrapVo;
import com.yhb.model.User;
import com.yhb.service.SplittingService;
import com.yhb.utils.DateUtils;
import me.edzh.spring.bootstrap.annotations.CurrentUser;
import me.edzh.spring.bootstrap.annotations.NeedAuth;
import me.edzh.spring.bootstrap.controller.BaseController;
import me.edzh.spring.bootstrap.model.Response;
import me.edzh.spring.bootstrap.service.ObjectiveStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/income")
public class IncomeController extends BaseController {


    @Autowired
    private SplittingService splittingService;

    @Qualifier("ossServiceImpl")
    @Autowired
    private ObjectiveStorageService objectiveStorageService;

    @GetMapping("/summary")
    @NeedAuth
    public Response<SingleValueWrapVo<String>> summary(@CurrentUser User user) {

        return Response.ok(
                new SingleValueWrapVo<>(
                        objectiveStorageService.signUrl("https://private.static.ylmvip.cn/" +
                                splittingService.getReportSummaryKey(user.getId())) // todo 改成数据库配置
                ));
    }


    @GetMapping("/{monthString}/detail")
    @NeedAuth
    public Response<SingleValueWrapVo<String>> detailIncome(@CurrentUser User user,
                                                            @PathVariable("monthString") String monthString) {
        return Response.ok(
                new SingleValueWrapVo<>(
                        objectiveStorageService.signUrl("https://private.static.ylmvip.cn/" +
                                splittingService.getReportDetailKey(monthString, user.getId()))
                ));
    }

}
